
#include <stdio.h>

int ERROR = 0;

int StrToInt(const char *str)
{
	static const int MAX_INT = (int)((unsigned)~0 >> 1);
	static const int MIX_INT = -(int)((unsigned)~0 >> 1) - 1;
	int n = 0;
	int sign = 1;

	if (str == 0)
		return 0;

	while (' ' == *str)
	{
		++str;
	}

	if (*str == '-' || *str == '+')
	{
		if (*str == '-')
			sign = -1;
		str++;
	}

	while (*str != '\0')
	{
		if (*str > '9')
		{
			ERROR = 1;
			return 0;
		}

		int c = *str - '0';
		if (sign > 0 && (n > MAX_INT / 10) || (n == MAX_INT / 10 && c > MAX_INT % 10))
		{
			n = MAX_INT;
			break;
		}
		else if (sign < 0 && (n < MIX_INT / 10) || (n == (unsigned)MIX_INT / 10 && c > MIX_INT % 10))
		{
			n = MIX_INT;
			break;
		}
		n = n * 10 + c;
		str++;
	}
	return sign > 0 ? n : -n;
}

int main()
{
	char str[] = "23";
	int sum;
	if (ERROR)
	{
		printf("Invaild Input");
	}
	else
	{
		sum = StrToInt(str);
		printf("%d", sum);
	}

	return 0;
}
